const ENCODE_KEY = "adcc";
//密码校验正则
const regex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,}$/

function encrypt(params,ENCODE_KEY1){
    let key = CryptoJS.enc.Utf8.parse(ENCODE_KEY1+ENCODE_KEY)
    let encrypted  = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(params), key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    })
    return  CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
}
function decode(params,ENCODE_KEY1) {
    let key1 = CryptoJS.enc.Utf8.parse(ENCODE_KEY1+ENCODE_KEY)
    let decrypt  = CryptoJS.AES.decrypt( params, key1, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    })
    return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}

function genAesSecret(){
    let key = "";
    $.ajax({
        url: "genaessecret",
        type: "post",
        async: false,
        data: {},
        dataType: "json",
        success: function (data) {
            let status = data.status
            if(status == 0){
                key = data.key
            }else{
                alert("服务器异常，请稍后重试!");
            }
        },
        error: function () {
            alert("服务器异常，请稍后重试!");
        }
    })
    return key
}

function getMessage(type){
    let message = ""
    switch (type){
        case 1:
            message = "服务异常，请稍后重试！"
            break
        case 2 :
            message = "用户名或密码错误！"
            break
        case 3 :
            message = "用户名或密码错误！"
            break
        case 4 :
            message = "验证码错误！"
            break
        case 5 :
            message = "用户不存在！"
            break
        case 6 :
            message = "旧密码错误！"
            break
        case 7 :
            message = "新密码不能为空！"
            break
        case 8 :
            message = "确认密码不能为空！"
            break
        case 9 :
            message = "两次输入新密码不一致！"
            break
        case 12 :
            message = "登录锁定，"
            break
        default :
            break
    }
    return message
}